package com.ec.rs.controller;

import com.ec.common.domain.PageVO;
import com.ec.common.domain.Result;
import com.ec.rs.domain.dto.CheckInOutRequestDTO;
import com.ec.rs.domain.dto.ReviewRequestDTO;
import com.ec.rs.domain.po.CheckInOutRequest;
import com.ec.rs.service.ResidenceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


@Api(tags = "探访与入住相关接口")
@RestController
@RequestMapping("/residence")
@RequiredArgsConstructor
@Slf4j
public class ResidenceController {
    private final ResidenceService residenceService;

    @ApiOperation("提交入住/退住申请")
    @PostMapping("/check-in-out-requests")
    public Result<Void> submitRequest(@RequestBody CheckInOutRequestDTO dto) {
        return residenceService.submitRequest(dto);
    }

    @ApiOperation("审核入住/退住申请")
    @PutMapping("/check-in-out-requests/{id}/review")
    public Result<Void> reviewRequest(@PathVariable Long id, @RequestBody ReviewRequestDTO dto) {
        return residenceService.reviewRequest(id, dto);
    }

    @ApiOperation("分页查询入住/退住申请")
    @GetMapping("/check-in-out-requests")
    public Result<PageVO<CheckInOutRequest>> listRequests(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size,
            @RequestParam(required = false) String requestType,
            @RequestParam(required = false) String status) {
        return residenceService.listRequests(page, size, requestType, status);
    }
}
